package com.work.task.ssh;

import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * shell脚本执行结果<br/>
 * 先通过getSuccess方法判断命令是否执行成功<br/>
 * 执行成功的时候采用result作为返回值<br/>
 * 执行不成功采用errorOut作为返回值<br/>
 *
 */
public class ShellResult implements Serializable {

    private static final long serialVersionUID = -110281463872334425L;

    /** 脚本输出结果 */
    private String result;
    /** 异常输出结果 */
    private String errorMsg;
    /** 回话退出状态 */
    private int exitStatus;

    public ShellResult() {
    }

    public ShellResult(String result, String errorOut, int exitStatus) {

        if (StringUtils.isEmpty(result)){
            this.result = result;
        }else{
            this.result = result.trim();
        }
        if (StringUtils.isEmpty(errorOut)){
            this.errorMsg = errorOut;
        }else{
            this.errorMsg = errorOut.trim();
        }
        this.exitStatus = exitStatus;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result.trim();
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg.trim();
    }

    public int getExitStatus() {
        return exitStatus;
    }

    public void setExitStatus(int exitStatus) {
        this.exitStatus = exitStatus;
    }

    /** 是否成功关闭会话 */
    public boolean getSuccess() {
        return this.exitStatus == 0;
    }
}

